<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<html:html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>
  <bean:message key="F0405.title"/>
  </title>
  <META http-equiv=Pragma content=no-cache>
  <META http-equiv=Cache-Control content=no-cache>
  <META http-equiv=Expires content=0>
  <link rel="stylesheet"
		href="<%=request.getContextPath()%>/resource/css/style.css"
		type="text/css">
  <script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/js/util.js"></script>
  <script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/style/scripts/util.js"></script>
  <script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/js/Validator.js"></script>
  <script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/calendar/DCDA_C03.js"></script>
	<%------------- -----------------------------------动态加载start----------------------------------------------------------------------%> 		
	<script language="javascript" type="text/javascript"
		src="<%=request.getContextPath()%>/resource/js/AdyhUtil.js"></script>	
	<script type="text/javascript"
		src="<%=request.getContextPath()%>/style/ext/adapter/ext/ext-base.js"></script>
	<script type="text/javascript"
		src="<%=request.getContextPath()%>/style/ext/ext-all.js"></script>	
<%------------------------------------------------动态加载end----------------------------------------------------------------------%>
  <script>
  
  //------------------------------------------------动态加载start---------------------------------------------------------------------- 
//动态加载 
function FiltSupplier(obj)
  {  	//
  		if(event.keyCode==38||event.keyCode==40||event.keyCode==13){
			keyEnter();
			if(numsup>=0&&(event.keyCode==38||event.keyCode==40)){
				document.getElementById("row"+numsup).focus();
				document.getElementById("row"+numsup).scrollIntoView(false);
			}
			return;
		}
  		
		var strValue = Jtrim(obj.value);   
		if(strValue==""){//检索条件为空时，不检索
			return ;
		}
		var strId =  obj.name;
		  
		//回显的编码的字段名称
		var strCode = "";
		//回显的名称的字段名称
		var strName = "";
		//相应的div的名称
		var strObj = "rtnList";
		
		strTextName=strId
		
		//供应商
		if(strId=='supplierName'){
			strCode = "supplierCode";
			strName = "supplierName";
			
		//材料
		}else if(strId=='materialName'){
			strCode = "materialCode";
			strName = "materialName";
		}
		
   		Ext.Ajax.request(
   		{
		url : 'F0405.do' , 
		params : {operationType:'ajax',id:strId,name:strValue},
		method: 'POST',
		success: function ( result, request) 
			{
			var listArray = new Array();
			var obj= Ext.decode(result.responseText) ;
			var objPrompt = document.getElementById(strObj);			
			objPrompt.style.display = "block";		
			objPrompt.innerHTML = "";
			initPosition(strObj);
			listArray = obj.data.list;
			var inn = "<table WIDTH=\"100%\" BORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"1\" bgcolor=\"#FFFFFF\" id=\"sup\" class=\"ListBackground\">";
 	        for (i=0; i<listArray.length; i++){
				inn += "<tr class=\"ListRow1\" height=\"20\" id=\"row"+(i)+"\"  onClick=\"javascript:show('"+strObj+"','"+listArray[i][0]+"','"+strCode+"','"+listArray[i][1]+"','"+strName+"')\">";
				inn += "<td>";
				inn += listArray[i][1];
				inn += "</td>";
				inn += "</tr>";
			}
			inn+="</table>";
			
			rownum=i;//获取动态加载的行数
			
			//若检索的结果是空，关闭div
			if(listArray.length==1&&listArray[0][0]==""&&listArray[0][1]==""){
				inn = "";
			}
			
			objPrompt.innerHTML += inn;
			if(rownum>0&&inn!=""){
				document.getElementById("row0").focus();
			}
			FocusTableRow1("sup",0);//鼠标划过变色
			setPosition(strObj,strName);	//设置div的位置	
			
			},	
		failure: function ( result, request) { 
			alert("<bean:message key="F020106.title"/>");
			} 
		}
		);
  }

//初始化div的位置
  function initPosition(strObj){
	var objPrompt = document.getElementById(strObj);
	objPrompt.style.top=0;
	objPrompt.style.left=0;
  }
  
  //设置div的位置
  function setPosition(strObjPrompt,strObjText){
  	var objPrompt = document.getElementById(strObjPrompt);
	var objText = document.getElementById(strObjText);
	objPrompt.style.top = 20-(objPrompt.offsetTop-objText.offsetTop);
	objPrompt.style.left = objText.offsetLeft-18;
  }
  
  //设置div的位置
  function initColumn(){
  		if(strTextName=='supplierName'){
			strCode = "supplierCode";
			strName = "supplierName";
			
		//材料
		}else if(strTextName=='materialName'){
			strCode = "materialCode";
			strName = "materialName";
		}
  	document.getElementById(strCode).value = "";
	document.getElementById(strName).value = "";
  }
  

//------------------------------------------------动态加载end----------------------------------------------------------------------

/**保存*/
function ShowAlert()
{	
	ResetMe();
	var supplierCode = Jtrim(document.getElementById("supplierCode").value);
	var supplierName = Jtrim(document.getElementById("supplierName").value);
	var materialCode = Jtrim(document.getElementById("materialCode").value);
	var materialName = Jtrim(document.getElementById("materialName").value);
	
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "block";
    objPrompt.innerHTML = "";
	
	if(supplierCode.length==0||supplierName.length==0||materialCode.length==0||materialName.length==0){
		if(supplierCode.length==0){
			objPrompt.innerHTML += "<li><bean:message key="F0404.supplierCode"/><bean:message key="adyh.error.isnull"/>！";
			//document.getElementById("supplierCode").className = "MyControlError";
		}		
		if(supplierName.length==0){
			objPrompt.innerHTML += "<li><bean:message key="F0404.supplierName"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("supplierName").className = "MyControlError";
		}
		if(materialCode.length==0){
			objPrompt.innerHTML += "<li><bean:message key="adyh.materialCode"/><bean:message key="adyh.error.isnull"/>！";
			//document.getElementById("materialCode").className = "MyControlError";
		}		
		if(materialName.length==0){
			objPrompt.innerHTML += "<li><bean:message key="adyh.materialName"/><bean:message key="adyh.error.isnull"/>！";
			document.getElementById("materialName").className = "MyControlError";
		}
	}else{
		var operationType = document.getElementById("operationType").value;
		document.getElementById("supplierCode").value = supplierCode;
		document.getElementById("supplierName").value = supplierName;
		document.getElementById("materialCode").value = materialCode;
		document.getElementById("materialName").value = materialName;
		operation("update");
	}
}

/**重置*/
function ResetMe()
{
    //document.getElementById("supplierCode").className = "MyText";
	document.getElementById("supplierName").className = "MyText";
	//document.getElementById("materialCode").className = "MyText";
	document.getElementById("materialName").className = "MyText";
	
	var objPrompt = document.getElementById("divPrompt");
    objPrompt.style.display = "none";
	objPrompt.innerHTML = "";
}
function ShowFormTitle(strTitle)
{
	document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" style=\"height:26px; background-position: left bottom; background-image: url(../../resource/image/FormTitle_A_4.gif); background-repeat: repeat-x;\">");
	document.write("  <tr >");
	document.write("	<td style=\"width:5px; background-position: left bottom; background-image: url(../../resource/image/FormTitle_A_1.gif); background-repeat: no-repeat;\">&nbsp;&nbsp;&nbsp;</td>");
	document.write("	<td class=\"FormTitle\" style=\"width:100%; padding-left:5px; padding-top:3px; background-position: left bottom; background-image: url(../../resource/image/FormTitle_A_2.gif); background-repeat: no-repeat;\">");
	document.write("		<span id=\"spanFormTitle\" class=\"SpanTitle\">"+ strTitle +"</span>");
	document.write("	</td>");
	document.write("	<td style=\"width:5px; background-position: right bottom; background-image: url(../../resource/image/FormTitle_A_3.gif); background-repeat: no-repeat;\">&nbsp;&nbsp;&nbsp;</td>");
    document.write("  </tr>");
	document.write("</table>");
}
</script>
  </head>
  <body>
  <html:form method="post" action="/pages/F04/F0405.do">
    <html:hidden property="operationType" />
    <html:hidden property="errorFlag" />
	<html:hidden property="supplierCode" />
	<html:hidden property="language"/>
    <html:hidden property="materialCode" />
    <!--Begin：表单标题-->
    <div class="DivBlock">
      <script language="javascript" type="text/javascript">
		ShowFormTitle("<bean:message key="F0405.title"/>");
	</script>
    </div>
    <!--End：表单标题-->
    <!--Begin：表单主体区块-->
    <div class="DivBlock">
      <div class="DivWrap" style="display:block">
        <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
          <TR>
            <TD ALIGN="right" NOWRAP><bean:message key="F0404.supplierName"/></TD><!--供应商名称-->
            <TD ALIGN="left" NOWRAP><html:text property="supplierName" styleClass="MyText" maxlength="50" onkeyup="FiltSupplier(this)" ondblclick="FiltSupplier(this)" style="position:relative"  onblur="loseFocus('rtnList')" />
              <span class="Need">*</span></TD>
            <TD ALIGN="right" NOWRAP><bean:message key="adyh.materialName"/></TD><!--材料名称-->
            <TD ALIGN="left" NOWRAP><html:text property="materialName" styleClass="MyText" maxlength="50" onkeyup="FiltSupplier(this)" ondblclick="FiltSupplier(this)" style="position:relative"  onblur="loseFocus('rtnList')" />
              <span class="Need">*</span></TD>
          </TR>
        </TABLE>
      </div>
    </div>
    <!--End：表单主体区块-->
    <!--Begin：表单按钮及提示区-->
    <div class="DivBlock">
      <div class="DivButton">
        <input type="button" name="Submit1" class="MyButton"
					onClick="ShowAlert()" value="<bean:message key="common.save"/>">
        <input type="button" name="Submit2" class="MyButton" value="<bean:message key="common.back"/>"
        onClick="javascript:operation('detailBack');"> </div>
      <div class="DivPrompt" id="divPrompt" style="display:none"> </div>
    </div>
	<%------------- -----------------------------------动态加载start----------------------------------------------------------------------%>
		<div id="rtnList" style="display: black; position:relative; overflow:auto; width:130; height:240" onmouseleave="col(this);initColumn()">
		</div>
  <%------------------------------------------------动态加载end----------------------------------------------------------------------%>
  
    <!--End：表单按钮及提示区-->
  </html:form>
  </body>
</html:html>
<script language="javascript" type="text/javascript">
InitForm();
</script>
